-<%@page isELIgnored="false" pageEncoding="UTF-8" contentType="text/html; UTF-8" %>

<div>
    <a href="javascript:void(0)" class="easyui-linkbutton"
       data-options="iconCls:'icon-add'" onclick="openDialog()">添加</a>
    <a  href="javascript:void(0)" class="easyui-linkbutton"
        data-options="iconCls:'icon-remove'" onclick="doDelete()">批量删除</a>
</div>
<table id="albums"></table>
<div id="addBanner">
    <form id="myForm" style="margin:30px" enctype="multipart/form-data" method="post">
        <table>
            <tr>
                <td>轮播图图片：<input name="bannerImageUrl" type="file"/></td>
            </tr>
            <tr>
                <td>轮播图名字：<input name="bannerOldName" /></td>
            </tr>
            <tr>
                <td>轮播图上传时间：<input name="bannerDate" /></td>
            </tr>
            <tr>
                <td>轮播图描述：<input name="bannerDescription" /></td>
            </tr>
        </table>
        <center>
            <a href="javascript:void(0)" class="easyui-linkbutton" iconCls="icon-save" onClick="add()">确认</a>
            <a href="javascript:void(0)" class="easyui-linkbutton" iconCls="icon-cancel">取消</a>
        </center>
    </form>
</div>

<%--<div id="updateBanner">--%>
    <%--<form id="myForm2"enctype="multipart/form-data" method="post">--%>
        <%--<table>--%>
            <%--<tr>--%>
                <%--<input id="bid" type="hidden" name="bannerId"/>--%>
                <%--<td>轮播图图片：<input id="bimage" name="bannerImageUrl" type="file"/></td>--%>
            <%--</tr>--%>
            <%--<tr>--%>
                <%--<td>轮播图名字：<input id="bname" name="bannerOldName"/></td>--%>
            <%--</tr>--%>
            <%--<tr>--%>
                <%--<td>轮播图状态：<input id="bstatus" name="bannerState"/></td>--%>
            <%--</tr>--%>
            <%--<tr>--%>
                <%--<td>轮播图上传时间：<input id="bdate" name="bannerDate"/></td>--%>
            <%--</tr>--%>
            <%--<tr>--%>
                <%--<td>轮播图描述：<input id="bdesc" name="bannerDescription"/></td>--%>
            <%--</tr>--%>
        <%--</table>--%>
        <%--<center>--%>
            <%--<a href="javascript:void(0)" class="easyui-linkbutton" iconCls="icon-save" onClick="update()">确认</a>--%>
            <%--<a href="javascript:void(0)" class="easyui-linkbutton" iconCls="icon-cancel">取消</a>--%>
        <%--</center>--%>
    <%--</form>--%>
<%--</div>--%>

<script type="text/javascript">
    $(function(){
        $("#addBanner").dialog({
            width:600,
            height:450,
            title:"添加轮播图",
            closed:true
        });
        $("#updateBanner").dialog({
            width:600,
            height:450,
            title:"修改",
            closed:true,
        });

            $('#albums').datagrid({
                onDblClickRow: function(rowIndex,rowData){
                    $("#updateBanner").dialog("open");
                    $("#bid").val(rowData.bannerId);
                    $("#bimage").val(rowData.bannerImageUrl);
                    $("#bname").val(rowData.bannerOldName);
                    $("#bstatus").val(rowData.bannerState);
                    $("#bdate").val(rowData.bannerDate);
                    $("#bdesc").val(rowData.bannerDescription);
                },

                url:'${pageContext.request.contextPath}/cmfzAlbum/queryAllCmfzAlbum',
                pagination : true,
                pageList : [ 5, 10, 15, 20 ],
                pageSize : 5,
                javaType:"JSON",
                columns:[[
                    {checkbox:true},
                    {field:'albumId',title:'专辑id',width:100},
                    {field:'albumName',title:'专辑名',width:100},
                    {field:'albumAuthor',title:'专辑作者',width:100},
                    {field:'albumTeller',title:'专辑波音',width:100},
                    {field:'albumEpisodes',title:'专辑集数',width:100},
                    {field:'albumDate',title:'发布时间',width:100},
                    {field:'albumContent',title:'专辑描述',width:100},

                    {field:'albumStar',title:'专辑状态',width:100},
                    {title : "操作",field : "cz",formatter : function(value, row, index) {
                            return "<a href='deleteBanner?ids=" + row.albumId + "'>删除</a>&nbsp;&nbsp;<a href='javascript:void(0)' onclick='update()'>修改</a>";
                        }
                    }
                ]]
            });
        }
    )

//    删除
    function doDelete(){
        var idd = $("#banners").datagrid("getSelections");
        if(idd.length==0){
            //提示框
            $.messager.alert('提示框',"请选择要删除的信息",'warning');
        }else{
            //提示框
            $.messager.confirm('提示框',"确定要删除吗",function(d){
                if(d){
                    //存储所有的id
                    var id = new Array();
                    for(var i=0;i<idd.length;i++){
                        id[i]=idd[i].bannerId;
                    }
                    //alert(id);
                    $.ajax({
                        url:"${pageContext.request.contextPath}/banner/deleteBanner",
                        type:"post",
                        data:"id="+id,
                        success:function(data){
                            if(data){
                                $.messager.alert('提示框',"删除成功",'info');
                                $("#prodatagrid").datagrid("reload");
                            }else{
                                $.messager.alert('提示框',"删除失败",'warning');
                            }
                        }
                    });
                }
            });
        }
    }
    function openDialog(){
        $("#addBanner").dialog("open");
    }
    //添加
    function add(){
        $('#myForm').form('submit', {
            url:"${pageContext.request.contextPath}/banner/insertBanner",
            onSubmit: function(){
                return true;
            },
            success:function(data){
                if(add){
                    $.messager.alert('提示框',"添加成功",'info');
                    $("#banners").datagrid("reload");
                    $("#addBanner").dialog("close");
                }else{
                    $.messager.alert('提示框',"添加失败",'warning');
                }

            }
        });
    }
    function update(){
        $("#myForm2").form("submit",{
            url:"${pageContext.request.contextPath}/banner/updateBanenr",
            success:function(data){
                if(data){
                    $.messager.alert('提示框',"修改成功",'info');
                    $("#banners").datagrid("reload");
                    $("#updateBanner").dialog("close");
                }else{
                    $.messager.alert("提示框","修改失败","warning");
                }
            }
        });
    }
</script>